using System;
using System.Collections.Generic;
using System.Text;

namespace Decav.Geocoding
{
    /// <summary>
    /// Defines an address on a street.
    /// </summary>
    public class StreetAddress
    {
        public StreetAddress(
            string number, string streetPrefix, string street, string streetSuffix, string streetType)
        {
            if (number != null && number.Length == 0)
                number = null;

            if (streetPrefix != null && streetPrefix.Length == 0)
                streetPrefix = null;

            if (street != null && street.Length == 0)
                street = null;

            if (streetSuffix != null && streetSuffix.Length == 0)
                streetSuffix = null;

            if (streetType != null && streetType.Length == 0)
                streetType = null;

            _number = number;
            _prefix = streetPrefix;
            _street = street;
            _suffix = streetSuffix;
            _type = streetType;
        }

        /// <summary>
        /// Gets the number of the address on the street.
        /// </summary>
        public string StreetNumber
        {
            get
            {
                return _number;
            }
        }

        /// <summary>
        /// Gets the prefix of the street.
        /// </summary>
        public string StreetPrefix
        {
            get
            {
                return _prefix;
            }
        }

        /// <summary>
        /// Gets the name of the street.
        /// </summary>
        public string Name
        {
            get
            {
                return _street;
            }
        }

        /// <summary>
        /// Gets the type of the street, such as "Ave" or "St".
        /// </summary>
        public string StreetType
        {
            get
            {
                return _type;
            }
        }

        /// <summary>
        /// Gets the suffix of the street, such as "South" or "West".
        /// </summary>
        public string StreetSuffix
        {
            get
            {
                return _suffix;
            }
        }

        private string _suffix;
        private string _type;
        private string _street;
        private string _prefix;
        private string _number;

        /// <summary>
        /// Gets the full first line of the address.
        /// </summary>
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            if (StreetNumber != null)
                builder.AppendFormat("{0} ", StreetNumber);

            if (StreetPrefix != null)
                builder.AppendFormat("{0} ", StreetPrefix);

            if (Name != null)
                builder.AppendFormat("{0} ", Name);

            if (StreetSuffix != null)
                builder.AppendFormat("{0} ", StreetSuffix);

            if (StreetType != null)
                builder.AppendFormat("{0} ", StreetType);

            return builder.ToString().Trim();
        }
    }
}
